package org.lanqiao.cloudserviceb.controller;

import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.lanqiao.cloudcommon.api.IUserDubboService;
import org.lanqiao.cloudcommon.common.CommonResult;
import org.lanqiao.cloudserviceb.feign.service.IAFeignService;
import org.lanqiao.cloudserviceb.pojo.OrderList;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
public class
OrderController {
    /**
     * 远程服务
     */
    @DubboReference
    IUserDubboService  userDubboService;


    @Autowired
    IAFeignService  iaFeignService;

    @Autowired
    RocketMQTemplate rocketMQTemplate;




    @PostMapping("/orders")
    public  CommonResult  insert(@RequestBody OrderList order){
        //TODO 订单插入
        rocketMQTemplate.convertAndSend("order-topic","编号2的订单已经成功，请发邮件");
        rocketMQTemplate.syncSendOrderly("order-topic","编号2的订单已经成功，请发邮件2","a");

        return  CommonResult.SUCCESS("下订单成功");

    }


    @GetMapping("/orders")
    public CommonResult test(){
        return  CommonResult.SUCCESS("我是微服务B中的/orders");

    }


    @GetMapping("/orders/dubbo")
    public CommonResult dubbo(){
        String result =  userDubboService.sayHello(10L);
        return  CommonResult.SUCCESS("我是远程dubbo服务IUserDubboService",result);

    }








}
